using System;
using System.Collections.Generic;
using System.Text;
using GameShow.Forms;
using System.Windows.Forms;
using System.Threading;

namespace GameShow
{
    public class AppInstance
    {
        private static frmPlayer00 _Player00 = null;
        private static frmPlayer01 _Player01 = null;
        private static frmPlayer02 _Player02 = null;        
        private static frmPlayer03 _Player03 = null;
        private static frmPlayer04 _Player04 = null;
        private static frmSlideShow02 _Slide02 = null;
        private static frmEntertaiment _Entertaiment = null;
        private static frmQuestions _frmQuestion = null;
        private static frmQuestionEditor _frmQuestionEditor = null;
        public static int ClientType = global::GameShow.Properties.Settings.Default.ClientType; //CuongBM: =0 voi chay nhac
        public static int CurrentPackId = 0;
        public static string TeamName = string.Empty;
        public static void SetStartForm(frmBase form)
        {
            _Player00 = (frmPlayer00)form;
            _Player00.IsRunning = true;
        }

        public static void InitialForms()
        {
            ShowPlayer01(-1);            
            ShowPlayer02(1);
            ShowPlayer03(2);            
            ShowPlayer04(3);
            CloseForm(4);
        }

        public static void ShowEntertaiment(int formNumber)
        {
            _Entertaiment = (_Entertaiment == null) ? new frmEntertaiment() : _Entertaiment;
            CloseForm(formNumber);
            _Entertaiment.StartForm();
        }

        public static void ShowPlayer00(int formNumber)
        {
            _Player00 = (_Player00 == null) ? new frmPlayer00(formNumber) : _Player00;
            if (ClientType == 0)
            {
                //_Player00.ControlBox = true;
                _Player00.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            }
            CloseForm(formNumber);
            _Player00.StartForm();
        }

        public static void ShowPlayer01(int formNumber)
        {
            _Player01 = (_Player01 == null) ? new frmPlayer01(formNumber) : _Player01;
            if (ClientType == 0)
            {
                //_Player01.ControlBox = true;
                _Player01.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            }
            CloseForm(formNumber);
            _Player01.StartForm();
        }

        public static void ShowPlayer02(int formNumber)
        {            
            if (ClientType == 0)
            {
                _Slide02 = (_Slide02 == null) ? new frmSlideShow02(formNumber) : _Slide02;
                CloseForm(formNumber);                
                _Slide02.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                _Slide02.StartForm();
            }
            else
            {
                _Player02 = (_Player02 == null) ? new frmPlayer02(formNumber) : _Player02;
                CloseForm(formNumber);
                _Player02.StartForm();                
            }
        }

        public static void ShowPlayer03(int formNumber)
        {
            _Player03 = (_Player03 == null) ? new frmPlayer03(formNumber) : _Player03;
            if (ClientType == 0)
            {                
                _Player03.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            }
            CloseForm(formNumber);
            _Player03.StartForm();
        }

        public static void ShowPlayer04(int formNumber)
        {
            _Player04 = (_Player04 == null) ? new frmPlayer04(formNumber) : _Player04;
            if (ClientType == 0)
            {
                //_Player03.ControlBox = true;
                _Player04.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            }
            CloseForm(formNumber);
            _Player04.StartForm();
        }

        public static void CloseForm(int formNumber)
        {
            if (formNumber == 0 && _Player00 != null)
            {
                _Player00.Visible = false;
                _Player00.IsRunning = false;
                _Player00.StopForm();
            }

            if (formNumber == 1 && _Player01 != null)
            {                
                _Player01.Visible = false;                
                _Player01.IsRunning = false;
                _Player01.StopForm();
            }

            if (formNumber == 2)
            {
                if (ClientType == 0 && _Slide02 != null)
                {
                    _Slide02.Visible = false;
                    _Slide02.IsRunning = false;
                    _Slide02.StopForm();
                }
                if (ClientType != 0 && _Player02 != null)
                {
                    _Player02.Visible = false;                    
                    _Player02.IsRunning = false;
                    _Player02.StopForm();
                }
            }

            if (formNumber == 3 && _Player03 != null)
            {
                _Player03.Visible = false;                
                _Player03.IsRunning = false;
                _Player03.StopForm();
            }

            if (formNumber == 4 && _Player04 != null)
            {
                _Player04.Visible = false;
                _Player04.IsRunning = false;
                _Player04.StopForm();
            }

            if (formNumber == 5 && _Entertaiment != null)
            {
                _Entertaiment.Visible = false;
                _Entertaiment.IsRunning = false;
                _Entertaiment.StopForm();
            }
        }

        public static void CloseProgram()
        {
            if (_Player00 != null) _Player00.Dispose();
            //Application.Exit();
        }
    }
}
